package com.woniuxy.huayoung.controller;

import com.woniuxy.huayoung.entity.TravelNotesReview;
import com.woniuxy.huayoung.entity.TravelReview;
import com.woniuxy.huayoung.result.ResponseResult;
import com.woniuxy.huayoung.service.TravelNotesReviewService;
import com.woniuxy.huayoung.service.TravelReviewService;
import com.woniuxy.huayoung.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/travelreview")
public class TravelReviewController {
    //日志对象
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);
    @Resource
    private UserService userService;
    @Resource
    private TravelReviewService travelReviewService;

    @GetMapping("/findTravelReview")
    public ResponseResult<List<TravelReview>> findTravelReview(HttpServletRequest request){
        //得到token
        String token = request.getHeader("authorization");
        int uid = userService.findIdByToken(token);
        List<TravelReview> travelReviews = travelReviewService.findByUid(uid);
        return new ResponseResult<List<TravelReview>>(200,"查询成功",travelReviews);
    }

    //查询所有通过审核的游记游记
    @GetMapping("/findAll")
    public ResponseResult<List<TravelReview>> findAll(){
        List<TravelReview> reviews = travelReviewService.findAll();
        return new ResponseResult<List<TravelReview>>(200,"查询成功",reviews);
    }

    //查询所有要审核的游记
    @GetMapping("/verify")
    public ResponseResult<List<TravelReview>> verify(){
        List<TravelReview> reviews = travelReviewService.verify();
        return new ResponseResult<List<TravelReview>>(200,"查询成功",reviews);
    }

    //审核通过
    @PostMapping("/verifypass")
    public ResponseResult<List<TravelReview>> verifypass(@RequestBody Map<String, Integer> map){
        logger.debug(map.toString());
        Integer id = map.get("id");
        List<TravelReview> reviews = travelReviewService.verifypass(id);
        return new ResponseResult<List<TravelReview>>(200,"查询成功",reviews);
    }

    //审核不通过
    @PostMapping("/verifynotpass")
    public ResponseResult<List<TravelReview>> verifyNotPass(@RequestBody Map<String,Object> map){
        List<TravelReview> reviews = travelReviewService.verifynotpass(map);
        return new ResponseResult<List<TravelReview>>(200,"提交成功",reviews);
    }


}
